const fs = require('fs')
const path = require('path')

const root = path.join(__dirname, '../private/')

function getAccount() {
    return JSON.parse(fs.readFileSync(path.join(root, 'account.json'), 'utf8'))
}

function getToken() {
    return JSON.parse(
        fs.readFileSync(path.join(root, 'usertoken.json'), 'utf8')
    )
}

function getRole() {
    return JSON.parse(
        fs.readFileSync(path.join(root, 'role.json'), 'utf8')
    )
}

function setToken(username, token) {
    const tokens = getToken()
    tokens[username] = token
    fs.writeFileSync(path.join(root, 'usertoken.json'), JSON.stringify(tokens))
}

module.exports = {
    getAccount,
    getToken,
    setToken,
    getRole
}
